<!-- 福分规则管理 -->
<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <GzSearchForm :searchFunc="searchFunc" :resetFunc="()=>{searchData = {};gzThreeRef.clear()}" searchConditionNum="6">
        <a-form-item class="table-search-item">
          <GzTreeSelect ref="gzThreeRef" v-model:value="searchData['agentNo']" :isNeedDefault="false" />
        </a-form-item>
        <GzTextUp v-model:value="searchData['scoreRuleName']" placeholder="规则名称" />
        <a-form-item class="table-search-item">
          <a-select v-model:value="searchData['state']" placeholder="状态">
            <a-select-option value="">全部</a-select-option>
            <a-select-option :value="0">不启用</a-select-option>
            <a-select-option :value="1">启用</a-select-option>
          </a-select>
        </a-form-item>
      </GzSearchForm>

      <!-- 列表渲染 -->
      <GzTable
        ref="infoTableRef"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :table-columns="tableColumns"
        :search-data="searchData"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.key == 'state'">
            <GzTableColState :state="record.state" :show-switch-type="false"/>
          </template>
          <template v-if="column.key === 'overType'">
            <template v-if="record.overType == 0">领取后{{ record.overDays }}天过期</template>
            <template v-else-if="record.overType == 1">{{ dayjs(record.overTime).format('YYYY[年]M[月]D[日]') }}过期</template>
            <template v-else>领取后次季度首月月底过期</template>
          </template>
        </template>
      </GzTable>
    </a-card>
  </page-header-wrapper>
</template>

<script lang="ts" setup>
import dayjs from 'dayjs'
import { $getScoreRule,$scoreRuleState } from '@/api/score/scoreRule/index'
import { ref, reactive, getCurrentInstance } from 'vue'

const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties

const gzThreeRef = ref()
const infoTableRef = ref()

let tableColumns = reactive([
  { key: 'scoreRuleName', title: '规则名称',dataIndex: 'scoreRuleName' },
  { key: 'ruleKey', title: '规则key',dataIndex: 'ruleKey' },
  { key: 'overType', title: '过期规则',dataIndex: 'overType' },
  { key: 'agentNo', title: '机构号',dataIndex: 'agentNo' },
  { key: 'agentName', title: '机构名称',dataIndex: 'agentName' },
  { key: 'state', title: '状态',dataIndex: 'state' },
])

const searchData:any = ref({})

// 请求table接口数据
function reqTableDataFunc(params: any) {
  return $getScoreRule(params)
}

function searchFunc() {
  infoTableRef.value.refTable(true)
}
</script>
